﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OnlineManagement.Web.userControl
{
    public class BaseSowUserControl:BaseUserControl
    {

       
        public Guid SowID {
            get {
                if (Request.QueryString["id"] != null)
                {
                    string sowIdStr = Request.QueryString["id"].ToString();
                    Guid sowId;
                    if (Guid.TryParse(sowIdStr, out sowId)) {
                        return sowId;
                    }
                }
                return Guid.Empty;
            }
        }
        public int Order { 
            get {
                int _order=0;
                if(Request.QueryString["order"]!=null){
                    int.TryParse(Request.QueryString["order"].ToString(), out _order);
                }
                return _order;
            }
        }
      
        /// <summary>
        /// 母猪耳号
        /// </summary>
        public string BitID {
            get {
                System.Data.DataSet ds=  SowBasicInfo();
                string bitId = string.Empty;
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count>0)
                {
                    System.Data.DataRowCollection rowColls = ds.Tables[0].Rows;
                    bitId = rowColls[0]["BitID"].ToString();

                    this._pigPenName = rowColls[0]["CustomizeID"].ToString();
                    string typeName = rowColls[0]["TypeName"].ToString();
                    int.TryParse(rowColls[0]["FanQingCount"].ToString(),out _fanQingcount);
                    this._sowTypeName = typeName;


                    int.TryParse(rowColls[0]["PropagateStateOrder"].ToString(), out _propagateStateOrder);
                    //_hybridizationRecordIDStr = rowColls[0]["HybridizationRecordID"].ToString();
                }
                return bitId;
            }
        }
        /// <summary>
        /// 母猪猪舍名称
        /// </summary>
        private string _pigPenName;
        public string PigPenName
        {
            get{return _pigPenName;}
        }
        /// <summary>
        /// 猪舍编号
        /// </summary>
        private Guid _pigPenId;
        public Guid PigPenID { 
            get 
            { 
                return _pigPenId; 
            } 
        }

        private string _sowTypeName;
        public string SowTypeName { get { return _sowTypeName; } }

        private int _fanQingcount;
        public int FanQingCount { get{return _fanQingcount;} }

        /// <summary>
        /// 母猪繁殖状态编号
        /// 后备期-1,发情配种期-2,怀孕期-3,分娩期-4,哺乳期-5,空怀期-6
        /// </summary>
        private int _propagateStateOrder=0;
        public int PropagateStateOrder { get { return _propagateStateOrder; } }


        #region 乳猪断奶登记中需要的数据
      
        private Guid _hybridizationRecordID;
        /// <summary>
        /// 配种记录id
        /// </summary>
        public Guid HybridizationRecordID { get { return _hybridizationRecordID; } }
        
        private Guid _propagateRecordId;
        /// <summary>
        /// 母猪繁殖记录id
        /// </summary>
        public Guid PropagateRecordId { get { return _propagateRecordId; } }

        private string _childTypeName;
        private DateTime _childBornDate;
        private int _childDayOld=0;
        public string ChildPigType { 
            get 
            {
                try
                {
                    System.Data.DataSet ds = ChildBasicInfo();
                    if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
                    {
                        System.Data.DataRowCollection rowColls = ds.Tables[0].Rows;
                        _childTypeName = rowColls[0]["TypeName"].ToString();
                        if (DateTime.TryParse(rowColls[0]["PropagateDate"].ToString(), out _childBornDate))
                        {
                            _childDayOld = (DateTime.Now - _childBornDate).Days;
                        }
                        int.TryParse(rowColls[0]["KeepChildTotal"].ToString(), out _childTotalCount);
                        Guid.TryParse(rowColls[0]["HybrizationRecord"].ToString(), out _hybridizationRecordID);
                        Guid.TryParse(rowColls[0]["PropagateRecordId"].ToString(), out _propagateRecordId);
                    }
                    return _childTypeName;
                }
                catch (Exception ex) { return string.Empty; }
            } 
        }

      
        public int ChildDayOld {
            get { return _childDayOld; }    
        }
        private int _childTotalCount=0;
        public int ChildTotalCount { get { return _childTotalCount; } }

        #endregion
        #region private methods
        private System.Data.DataSet SowBasicInfo() {
            BLL.Sow bllSow = new BLL.Sow();
            System.Data.DataSet ds = null;
            if (this.SowID!=Guid.Empty)
            {
                ds = bllSow.GetSowBasicInfo(this.SowID, HoggeryID);
            }
            return ds;
        }

        private System.Data.DataSet ChildBasicInfo() {
            try
            {
                BLL.PropagateRecord bllPr = new BLL.PropagateRecord();
                System.Data.DataSet ds = bllPr.GetSpecificSowChildInfo(HoggeryID, SowID);
                return ds;
            }catch(Exception ex){
                throw ex;
            }
        }
        #endregion
    }

}